//
//  ChatViewController.m
//  QuickCure
//
//  Created by Ruihaha on 16/9/16.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "ChatViewController.h"
#import "ChatMessageCell.h"
#import "CaseManagerViewController.h"
#import "grayLabel.h"

@interface ChatViewController ()

@property(nonatomic,strong)UIScrollView * topView;
@property(nonatomic,strong)UIView * bottomView;
@property(nonatomic,strong)grayLabel * time;
@property(nonatomic,strong)UIImageView * send;
@end

@implementation ChatViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.navigationController.navigationBar.tintColor =WHITE_COLOR;
    self.view.backgroundColor = GRAY_COLOR;
}

-(void)setModel:(DoctorModel *)model{
    
    _model = model;
    
    [self setupUI];
    
    ChatMessageCell * cell = [[ChatMessageCell alloc]init];
    [self.topView addSubview:cell];
    cell.model = model;
    
    [cell makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_time.mas_bottom).offset(5);
        make.left.right.equalTo(self.topView);
        make.height.equalTo(100);
    }];

    
}
-(void)setupTopView{
    
    _time  = [[grayLabel alloc]init];
    [self.topView addSubview:_time];
    NSDate * date =[NSDate date];
    NSDateFormatter * formatter =[[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd  HH:mm:ss";
    NSString * dateStr = [formatter stringFromDate:date];
    _time.text = dateStr;
    
    [_time makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView).offset(10);
        make.centerX.equalTo(self.topView);
    }];

}
-(void)setupUI{

    self.topView = [[UIScrollView alloc]init];
    self.topView.pagingEnabled=NO;
    self.topView.backgroundColor = GRAY_COLOR;
    [self.view addSubview:self.topView];
    [self setupTopView];
    
    self.bottomView = [[UIView alloc]init];
    self.bottomView.backgroundColor=GRAY_COLOR;
    [self.view addSubview:self.bottomView];
    
    [self.topView makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(self.bottomView.mas_top);
    }];
    
    [self.bottomView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.height.equalTo(200);
    }];
    
    UIView * textView = [[UIView alloc]init];
    textView.backgroundColor=kThemeColor;
    [self.bottomView addSubview:textView];
    [textView makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.bottomView);
        make.height.equalTo(50);
    }];
    
    
    UITextField * textField = [[UITextField alloc]init];
    [textView addSubview:textField];
    
    
    UIButton * face = [[UIButton alloc]init];
    [textView addSubview:face];
    [face setImage:[UIImage imageNamed:@"qcall_smile_default_img"] forState:UIControlStateNormal];
    
    
    [face makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(textView).offset(5);
        make.right.equalTo(textView).offset(-10);
        make.size.equalTo(40);
    }];
    
    textField.background = [UIImage imageNamed:@"shurukuang"];
    [textField makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(textView).offset(5);
        make.left.equalTo(textView).offset(20);
        make.bottom.equalTo(textView).offset(-5);
        make.right.equalTo(face.mas_left).offset(-5);
        
    }];
    
    self.send = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"send"]];
    [self.bottomView addSubview:self.send];
    self.send.userInteractionEnabled=YES;
    UITapGestureRecognizer * tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(jumpToSelected)];
    [self.send addGestureRecognizer:tap];
    
    [self.send makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bottomView).offset(10);
        make.size.equalTo(80);
        make.centerY.equalTo(self.bottomView).offset(25);
    }];
    
}

-(void)jumpToSelected{

    CaseManagerViewController * caseManage = [[CaseManagerViewController alloc]init];
    
    [self.navigationController pushViewController:caseManage animated:YES];
}
@end
